package com.ctshk.rpc.scenic.mapper;

import com.ctshk.rpc.scenic.base.CustomBaseMapper;
import com.ctshk.rpc.scenic.entity.ScenicProductSaleStrategyVaildDate;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 门票销售价格加幅有效期 Mapper 接口
 * </p>
 *
 * @author wangcy
 * @since 2021-02-02
 */
public interface ScenicProductSaleStrategyVaildDateMapper extends CustomBaseMapper<ScenicProductSaleStrategyVaildDate> {
    /**
     * 批量插入
     *
     * @param entityList 实体列表
     * @return 影响行数
     */
    Integer insertBatchSomeColumn(Collection<ScenicProductSaleStrategyVaildDate> entityList);

    /**
     * 清空有效期
     * @param
     * @param
     */
    @Update("delete from t_scenic_product_sale_strategy_vaild_date \n" +
            "WHERE product_id = #{product_id}")
    Integer clearByProductId(@Param("product_id") Long productId, @Param("modified_id")Long userId);

    @Select("SELECT * from t_scenic_product_sale_strategy_vaild_date \n" +
            "WHERE DATE_FORMAT(#{time},'%Y-%m-%d') >=DATE_FORMAT(time_begin,'%Y-%m-%d')  \n" +
            "and  DATE_FORMAT(#{time},'%Y-%m-%d') <= DATE_FORMAT(time_end,'%Y-%m-%d') and product_id = #{productId} limit 1" )
    ScenicProductSaleStrategyVaildDate queryDetail(@Param("time") String time,@Param("productId") Long productId);

    @Select("SELECT * from t_scenic_product_sale_strategy_vaild_date \n" +
            "WHERE DATE_FORMAT(#{time},'%Y-%m-%d') >=DATE_FORMAT(time_begin,'%Y-%m-%d')  \n" +
            "and  DATE_FORMAT(#{time},'%Y-%m-%d') <= DATE_FORMAT(time_end,'%Y-%m-%d')" )
    List<ScenicProductSaleStrategyVaildDate> queryList(@Param("time") String time);

    @Select("SELECT * from t_scenic_product_sale_strategy_vaild_date \n" +
            "WHERE product_id = #{productId}" )
    ScenicProductSaleStrategyVaildDate queryDetailById(@Param("productId") Long productId);
}
